package DAO;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class BaseDao {
	final public static String DriverName="com.mysql.jdbc.Driver";
	public final static String URL="jdbc:mysql://localhost:3306/javaee";
	final static String userName="root";
	final static String passWord="root";
	static Connection con;
	static Statement stmt;
	static{
			con=Connect();
			try {
				stmt=con.createStatement();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	}
	protected static Connection Connect()
	{

       try {
			Class.forName(DriverName);
	       Connection con;
			con = DriverManager.getConnection(URL, userName, passWord);
	       return con;
		
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}catch (ClassNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
       return null;
	}
	protected static void close()
	{
		try {
			stmt.close();
			con.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public static ResultSet executeQuery(String sql) throws SQLException
	{		
		return stmt.executeQuery(sql);
	}
	public static int executeUpdate(String sql) throws SQLException
	{
		return stmt.executeUpdate(sql);
	}
	public static PreparedStatement prepareStatement(String sql) throws SQLException
	{
			return con.prepareStatement(sql);
	}
	 public static void main()
	 {
		 Connect();
	 }
}
